草庐IT

MongoDB $project : $filter sub-array

全部标签

mongodb - 如何更新文档中数组中的字段

我有一个具有以下结构的文档。我想在数组files中插入一个新文件,然后将所有其他文件状态设置为“INACTIVE”。插入后,我正在尝试使用以下代码更新数组的其他文件,但它无法匹配。{{"id":"fafsahjaf867rwhrbjw","files":[{"name":"123",status:"ACTIVE"},{"name":"124",status:"ACTIVE"},{"name":"125",status:"ACTIVE"},{"name":"126",status:"ACTIVE"},]},}query=bson.M{"id":productId,"files":bson

mongodb 获取最后 30 分钟前插入的项目

我想检查在过去30分钟内是否使用mongodb在golang中添加了项目。这是我的类型模型:typePayCoinstruct{IDbson.ObjectId`json:"id"bson:"_id"`OwnerIDbson.ObjectId`json:"owner_id"bson:"owner_id"`PublicKeystring`json:"public_key"bson:"public_key"`PrivateKeystring`json:"-"bson:"private_key"`QrCodestring`json:"qrcode"bson:"-"`ExchangeRateui

mongodb - 在集合中没有索引的情况下使用 golang mongo 时无法通过 tier.Next(&result) 获取值,如果索引已设置则获取值

我在使用gomongo操作时遇到问题。我的代码是这样的:iter=coll.Find(filter).Sort("-timestamp").Skip(12510).Limit(10).Iter()foriter.Next(&result){....}我收集了12520个文档,但如果我没有在MongoDB中设置timestamp的索引,则无法使用iter.Next()获取值。如果我设置“timestamp”的索引,这似乎可行,并且我可以获得结果的值(value)。那么,发生了什么事? 最佳答案 你需要先解码你的数据然后迭代它这里的it

mongodb - 无法通过 2sphere 找到元素

我来是因为我需要实现地理计算,但是,它不起作用。我目前正在使用包globalsign/mgo从文档我们有这个:db..find({:{$near:{$geometry:{type:"Point",coordinates:[,]},$maxDistance:,}}})查询2dsphere索引:https://docs.mongodb.com/manual/tutorial/query-a-2dsphere-index/2dsphere索引:https://docs.mongodb.com/manual/core/2dsphere/所以我有以下内容:import("github.com/g

go - 通过 SSH golang 连接到 mongoDB

我需要通过ssh连接到远程mongoDB服务器,我之前是用mysql做的,它看起来像:sshcon,err:=ssh.Dial("tcp",fmt.Sprintf("%s:%d",sshHost,sshPort),sshConfig)iferr==nil{defersshcon.Close()mysql.RegisterDial("mysql+tcp",(&ViaSSHDialer{sshcon}).Dial)mgo包里有类似mysql.RegisterDial的函数吗? 最佳答案 将隧道功能添加到您的代码中确实没有意义。一个简单的

arrays - 声明一个常量数组

我试过:constascii="abcdefghijklmnopqrstuvwxyz"constletter_goodness[]float32={.0817,.0149,.0278,.0425,.1270,.0223,.0202,.0609,.0697,.0015,.0077,.0402,.0241,.0675,.0751,.0193,.0009,.0599,.0633,.0906,.0276,.0098,.0236,.0015,.0197,.0007}constletter_goodness={.0817,.0149,.0278,.0425,.1270,.0223,.0202,.0

mongodb - mongodb文本搜索错误没有文本索引

我正在尝试使用mongodb文本搜索,但我收到以下消息错误-没有文本索引虽然可以看到db.items中有文本索引。有什么问题?Mongoose的命令是什么?>db.items.getIndexes()[{"v":1,"key":{"_id":1},"ns":"db.items","name":"_id_"},{"v":1,"key":{"type":"text","color":"text","category_A":"text","category_B":"text","category_C":"text"},"ns":"db.items","name":"type_text_col

mongodb - 如何使用 mgo 和 Go 查询具有日期范围的 MongoDB?

您好,我有一个名为“my_sales”的集合,其中包含字段product_name、price、sale_date。我的文档看起来像{"_id":ObjectId("5458b6ee09d76eb7326df3a4"),"product_name":product1,"price":200,"sale_date":ISODate("2014-11-04T11:22:19.589Z")}{"_id":ObjectId("5458b6ee09d76eb7326df3a4"),"product_name":product1,"price":200,"sale_date":ISODate("2

mongodb - $text 查询所需的 mongo-go-driver (IndexNotFound) 文本索引

我正在使用mongo-go-driver并尝试使用文本搜索我正在创建这样的索引opts:=options.CreateIndexes().SetMaxTime(10*time.Second)db.Collection("my_collection").Indexes().CreateMany(context.Background(),[]mongo.IndexModel{{Keys:bsonx.Doc{{"title",bsonx.Int32(-1)}},},{Keys:bsonx.Doc{{"info.tags",bsonx.Int32(-1)}},},},opts,)...在查询时

postgresql - 如何将 pq.Int64Array 转换为字符串?

在Golang应用程序中,我对PostgreSQL数据库进行sql查询,它返回了一个int数组。varidentifiers[]pq.Int64Array//ExecuteSQLqueryby"database/sql"package.iferr:=database.DBSQL.QueryRow(sqlStatement.String()).Scan(&identifiers);err!=nil{log.Println(err)utils.ResponseWithError(responseWriter,http.StatusInternalServerError,err.Error(